package com.services
{
	import flash.events.HTTPStatusEvent;
	
	import mx.controls.Alert;
	import mx.rpc.events.FaultEvent;
	import mx.rpc.events.ResultEvent;
	import mx.rpc.http.mxml.HTTPService;
	
	public class BasicService
	{
		private var _url:String;
		protected var service:HTTPService;
		protected var _callBack:Function = null;
		
		
		public function BasicService(url:String = null, method:String = "GET", busyCursor:Boolean = false, callBack:Function=null)
		{
			_url = url;
			_callBack = callBack;
			service = new HTTPService();
			service.method = method
			service.showBusyCursor = busyCursor;
			service.resultFormat = "object";
		}
		
		public function send(paramters:Object = null):void
		{
			service.url = _url;	
			service.addEventListener(ResultEvent.RESULT, resultHandler);
			service.addEventListener(FaultEvent.FAULT, faultHandler);
//			service.addEventListener(HTTPStatusEvent.HTTP_STATUS, statusHandler);
			service.send(paramters);			
		}
		
		public function resultHandler(event:ResultEvent):void
		{
			if(_callBack != null)
				_callBack.call(null);
		}
		
		public function faultHandler(event:FaultEvent):void
		{
			Alert.show(event.message.toString());
			if(_callBack != null)
				_callBack.call(null);	
		}
	}
}